package com.xyy.saas.payment.service.impl;

import com.xyy.saas.payment.dao.mapper.ApplyOpenAccountStatusMapper;
import com.xyy.saas.payment.dao.model.ApplyOpenAccountStatus;
import com.xyy.saas.payment.service.ApplyOpenAccountStatusService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

@Service
public class ApplyOpenAccountStatusServiceImpl implements ApplyOpenAccountStatusService {
    private static final Logger LOGGER = LoggerFactory.getLogger(ApplyOpenAccountStatusServiceImpl.class);

    @Autowired
    private ApplyOpenAccountStatusMapper applyOpenAccountStatusMapper;

    @Override
    public List<ApplyOpenAccountStatus> selectByParam(ApplyOpenAccountStatus param) {
        if(null == param) {
            return new ArrayList<>();
        }
        return applyOpenAccountStatusMapper.selectByParam(param);
    }

    @Override
    public List<ApplyOpenAccountStatus> queryByPage(int offset, int limit) {
        return applyOpenAccountStatusMapper.queryByPage(offset, limit);
    }

    @Override
    public List<ApplyOpenAccountStatus> queryByStatusPage(List<Integer> statusList, int offset, int limit) {
        return applyOpenAccountStatusMapper.queryByStatusPage(statusList, offset, limit);
    }

    @Override
    public ApplyOpenAccountStatus selectByApplyCode(String applyCode) {
        if(StringUtils.isEmpty(applyCode)) {
            return null;
        }
        return applyOpenAccountStatusMapper.selectByApplyCode(applyCode);
    }

    @Override
    public int insert(ApplyOpenAccountStatus entity) {
        if(null == entity) {
            return 0;
        }
        try {
            return applyOpenAccountStatusMapper.insert(entity);
        } catch (Exception e) {
            LOGGER.error("ApplyOpenAccountStatusServiceImpl#insert sql exception. ApplyOpenAccountStatus:{}, e:{}", entity, e);
            return 0;
        }
    }

    @Override
    public int updateByPrimaryKeySelective(ApplyOpenAccountStatus entity) {
        if(null == entity) {
            return 0;
        }
        try {
            return applyOpenAccountStatusMapper.updateByPrimaryKeySelective(entity);
        } catch (Exception e) {
            LOGGER.error("ApplyOpenAccountStatusServiceImpl#updateByPrimaryKeySelective sql exception. ApplyOpenAccountStatus:{}, e:{}", entity, e);
            return 0;
        }
    }

    @Override
    public int removeById(Long id) {
        if(null == id) {
            return 0;
        }
        try {
            return applyOpenAccountStatusMapper.removeById(id);
        } catch (Exception e) {
            LOGGER.error("ApplyOpenAccountStatusServiceImpl#removeById sql exception. id:{}", id, e);
            return 0;
        }
    }
}
